﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace 两数之和
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] s = new int[] { 2,6,77, 7, 11, 15 };
            int[] a = TwoSum(s, 9);
            Console.WriteLine("Hello World!{0},,{1}",a[0],a[1]);
            Console.ReadLine();
        }

        public static int[] TwoSum(int[] nums, int target)
        {
            Dictionary<int, int> dictionary = new Dictionary<int, int>();
            for (int i = 0; i < nums.Length; i++)
            {
                int temp = target - nums[i];
                if (dictionary.ContainsKey(temp))
                    return new int[] { dictionary[temp], i };
                dictionary[nums[i]] = i;
            }
            return null ;
        }
    }
}
